namespace Teleware.Newbe.Navigation.Web.Migrations
{
    using System;
    using System.Collections.Generic;
    using System.Data.Entity.Infrastructure.Annotations;
    using System.Data.Entity.Migrations;
    
    public partial class Db20171212 : DbMigration
    {
        public override void Up()
        {
            DropForeignKey("dbo.QqGroupInfoes", "CreatorUserId", "dbo.Accounts");
            DropForeignKey("dbo.QqGroupInfoes", "DeleterUserId", "dbo.Accounts");
            DropForeignKey("dbo.QqGroupInfoes", "DepartmentId", "dbo.Departments");
            DropForeignKey("dbo.QqGroupInfoes", "LastModifierUserId", "dbo.Accounts");
            DropForeignKey("dbo.QqGroupInfoTags", "InfoTagId", "dbo.InfoTags");
            DropForeignKey("dbo.QqGroupInfoTags", "QqGroupInfoId", "dbo.QqGroupInfoes");
            DropForeignKey("dbo.QqInfoes", "CreatorUserId", "dbo.Accounts");
            DropForeignKey("dbo.QqInfoes", "DeleterUserId", "dbo.Accounts");
            DropForeignKey("dbo.QqInfoes", "DepartmentId", "dbo.Departments");
            DropForeignKey("dbo.QqInfoes", "LastModifierUserId", "dbo.Accounts");
            DropForeignKey("dbo.QqInfoTags", "InfoTagId", "dbo.InfoTags");
            DropForeignKey("dbo.QqInfoTags", "QqInfoId", "dbo.QqInfoes");
            DropIndex("dbo.QqGroupInfoes", new[] { "DepartmentId" });
            DropIndex("dbo.QqGroupInfoes", new[] { "CreatorUserId" });
            DropIndex("dbo.QqGroupInfoes", new[] { "LastModifierUserId" });
            DropIndex("dbo.QqGroupInfoes", new[] { "DeleterUserId" });
            DropIndex("dbo.QqGroupInfoTags", new[] { "QqGroupInfoId" });
            DropIndex("dbo.QqGroupInfoTags", new[] { "InfoTagId" });
            DropIndex("dbo.QqInfoes", new[] { "DepartmentId" });
            DropIndex("dbo.QqInfoes", new[] { "CreatorUserId" });
            DropIndex("dbo.QqInfoes", new[] { "LastModifierUserId" });
            DropIndex("dbo.QqInfoes", new[] { "DeleterUserId" });
            DropIndex("dbo.QqInfoTags", new[] { "InfoTagId" });
            DropIndex("dbo.QqInfoTags", new[] { "QqInfoId" });
            AddColumn("dbo.HrefInfoes", "Content", c => c.String(nullable: false));
            DropTable("dbo.QqGroupInfoes",
                removedAnnotations: new Dictionary<string, object>
                {
                    { "DynamicFilter_QqGroupInfo_SoftDelete", "EntityFramework.DynamicFilters.DynamicFilterDefinition" },
                });
            DropTable("dbo.QqGroupInfoTags");
            DropTable("dbo.QqInfoes",
                removedAnnotations: new Dictionary<string, object>
                {
                    { "DynamicFilter_QqInfo_SoftDelete", "EntityFramework.DynamicFilters.DynamicFilterDefinition" },
                });
            DropTable("dbo.QqInfoTags");
        }
        
        public override void Down()
        {
            CreateTable(
                "dbo.QqInfoTags",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        InfoTagId = c.String(nullable: false, maxLength: 128),
                        QqInfoId = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.QqInfoes",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 128),
                        Qq = c.String(nullable: false),
                        Name = c.String(nullable: false),
                        Remark = c.String(),
                        DepartmentId = c.String(nullable: false, maxLength: 128),
                        CreationTime = c.DateTime(nullable: false),
                        CreatorUserId = c.Long(),
                        LastModificationTime = c.DateTime(),
                        LastModifierUserId = c.Long(),
                        IsDeleted = c.Boolean(nullable: false),
                        DeletionTime = c.DateTime(),
                        DeleterUserId = c.Long(),
                        OrderNo = c.String(),
                    },
                annotations: new Dictionary<string, object>
                {
                    { "DynamicFilter_QqInfo_SoftDelete", "EntityFramework.DynamicFilters.DynamicFilterDefinition" },
                })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.QqGroupInfoTags",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        QqGroupInfoId = c.String(nullable: false, maxLength: 128),
                        InfoTagId = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.QqGroupInfoes",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 128),
                        QqGroup = c.String(nullable: false),
                        QqGroupLink = c.String(),
                        Name = c.String(nullable: false),
                        Remark = c.String(),
                        DepartmentId = c.String(nullable: false, maxLength: 128),
                        CreationTime = c.DateTime(nullable: false),
                        CreatorUserId = c.Long(),
                        LastModificationTime = c.DateTime(),
                        LastModifierUserId = c.Long(),
                        IsDeleted = c.Boolean(nullable: false),
                        DeletionTime = c.DateTime(),
                        DeleterUserId = c.Long(),
                        OrderNo = c.String(),
                    },
                annotations: new Dictionary<string, object>
                {
                    { "DynamicFilter_QqGroupInfo_SoftDelete", "EntityFramework.DynamicFilters.DynamicFilterDefinition" },
                })
                .PrimaryKey(t => t.Id);
            
            DropColumn("dbo.HrefInfoes", "Content");
            CreateIndex("dbo.QqInfoTags", "QqInfoId");
            CreateIndex("dbo.QqInfoTags", "InfoTagId");
            CreateIndex("dbo.QqInfoes", "DeleterUserId");
            CreateIndex("dbo.QqInfoes", "LastModifierUserId");
            CreateIndex("dbo.QqInfoes", "CreatorUserId");
            CreateIndex("dbo.QqInfoes", "DepartmentId");
            CreateIndex("dbo.QqGroupInfoTags", "InfoTagId");
            CreateIndex("dbo.QqGroupInfoTags", "QqGroupInfoId");
            CreateIndex("dbo.QqGroupInfoes", "DeleterUserId");
            CreateIndex("dbo.QqGroupInfoes", "LastModifierUserId");
            CreateIndex("dbo.QqGroupInfoes", "CreatorUserId");
            CreateIndex("dbo.QqGroupInfoes", "DepartmentId");
            AddForeignKey("dbo.QqInfoTags", "QqInfoId", "dbo.QqInfoes", "Id", cascadeDelete: true);
            AddForeignKey("dbo.QqInfoTags", "InfoTagId", "dbo.InfoTags", "Id", cascadeDelete: true);
            AddForeignKey("dbo.QqInfoes", "LastModifierUserId", "dbo.Accounts", "Id");
            AddForeignKey("dbo.QqInfoes", "DepartmentId", "dbo.Departments", "Id", cascadeDelete: true);
            AddForeignKey("dbo.QqInfoes", "DeleterUserId", "dbo.Accounts", "Id");
            AddForeignKey("dbo.QqInfoes", "CreatorUserId", "dbo.Accounts", "Id");
            AddForeignKey("dbo.QqGroupInfoTags", "QqGroupInfoId", "dbo.QqGroupInfoes", "Id", cascadeDelete: true);
            AddForeignKey("dbo.QqGroupInfoTags", "InfoTagId", "dbo.InfoTags", "Id", cascadeDelete: true);
            AddForeignKey("dbo.QqGroupInfoes", "LastModifierUserId", "dbo.Accounts", "Id");
            AddForeignKey("dbo.QqGroupInfoes", "DepartmentId", "dbo.Departments", "Id", cascadeDelete: true);
            AddForeignKey("dbo.QqGroupInfoes", "DeleterUserId", "dbo.Accounts", "Id");
            AddForeignKey("dbo.QqGroupInfoes", "CreatorUserId", "dbo.Accounts", "Id");
        }
    }
}
